package com.aaa.order.service;



import com.aaa.entity.order.TOrder;

import com.aaa.order.feign.OrderFiegnClient;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;


import java.util.List;


@Service
public class OrderService {

//    @Autowired
//    DiscoveryClient discoveryClient;
//负载均衡
//    @Autowired
//    LoadBalancerClient loadBalancerClient;
//
//    @Autowired
//    RestTemplate restTemplate;

    @Autowired
    OrderFiegnClient orderFiegnClient;


    public String findInfo(Long orderId) {
        TOrder tOrder = new TOrder();
        return "111";

    }
  //进行流量保护 value = 自定义资源名
    @SentinelResource(value = "getProdUctById")
    public String getProdUctById(Long orderId) {
        String aaa=  orderFiegnClient.getProdUctById(orderId);
        return aaa;

    }

//    public String getShopFrom() {
//        //读取user服务所在的信息
//       List<ServiceInstance> user = discoveryClient.getInstances("user");
//       ServiceInstance serviceInstance = user.get(0);
//       return  serviceInstance.getHost() + ","+serviceInstance.getPort();
//   }

 // 轮询 负载均衡
//    public String getChoose() {
//        ServiceInstance choose = loadBalancerClient.choose("user");
//        String url = "http://" + choose.getHost() + ":" + choose.getPort() + "/user/findShop";
//        System.out.println(url);
//        String forObject = restTemplate.getForObject(url, String.class);
//        return forObject;
//    }

    // 基于注解
//    public String getChooseTwo() {
//
//        // http + 服务名（会被动态替换复制） + 接口地址
//        String url = "http://user/user/findShop";
//        System.out.println(url);
//        String forObject = restTemplate.getForObject(url, String.class);
//        return forObject;
//    }
}
